{include file="public/layout" /}

<body class="bodystyle" style="overflow-y: scroll;">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
{include file="shop/left" /}
<div class="page">
    <div class="flexigrid htitx">
        <form class="form-horizontal" id="post_form" action="{:url('Shop/conf')}" method="post">
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                        <tr>
                            <th class="sign w10" axis="col0">
                                <div class="tc"></div>
                            </th>
                            <th abbr="article_title" axis="col3" class="w10">
                                <div class="tc">基本设置</div>
                            </th>
                            <th abbr="ac_id" axis="col4">
                                <div class=""></div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">标签调用</dt>
                    <dd class="opt">
                        <a href="javascript:void(0);" onclick="tag_call('shop_open');" class="ncap-btn ncap-btn-green">查看标签</a>
                        <p class="notic">请确保商城模板已经调用购买行为的标签，里面包含规格、数量、价格等！</p>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="uname">商家提示</label>
                    </dt>
                    <dd class="opt">
                        <textarea name="shop[shop_prompt]" placeholder="此处文字将显示在会员下单确认页面上" style="width: 30%; height: 60px;">{$userConfig.shop_prompt}</textarea>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="uname">货到付款</label>
                    </dt>
                    <dd class="opt">
                        <label>
                            <input type="radio" name="shop[shop_open_offline]" value="0" {if condition="!isset($userConfig.shop_open_offline) || empty($userConfig.shop_open_offline)"}checked="checked"{/if}/>开启
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="shop[shop_open_offline]" value="1" {if condition="$userConfig.shop_open_offline == 1"}checked="checked"{/if}/>关闭
                        </label>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit"><label>原路退回</label></dt>
                    <dd class="opt">
                        <label>
                            <input type="radio" name="pay[pay_original_refund]" value="1" {if condition="$userConfig.pay_original_refund == 1"} checked="checked" {/if}/>开启
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="pay[pay_original_refund]" value="0" {if condition="!isset($userConfig.pay_original_refund) || empty($userConfig.pay_original_refund)"} checked="checked" {/if}/>关闭
                        </label>
                        <p class="notic2">后台执行订单退款操作时，退款金额支持原路退回。目前仅微信支付的订单支持原路退回</p>
                    </dd>
                </dl>

                <input type="file" id="apiclientClickID" onchange="apiclientClick(this);" style="display: none;">
                <dl class="row openOriginalRefund none">
                    <dt class="tit"><label for="wechat_apiclient_cert">apiclient_cert</label></dt>
                    <dd class="opt">
                        <input type="hidden" name="pay[pay_wechat_apiclient_cert]" id="wechat_apiclient_cert" value="{$userConfig.pay_wechat_apiclient_cert|default=''}">
                        <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" onclick="$('#apiclientClickID').attr('data-type', 'apiclient_cert').trigger('click');">{empty name="$userConfig.pay_wechat_apiclient_cert"}点击上传{else/}重新上传{/empty}</a>
                        <span style="{empty name='$userConfig.pay_wechat_apiclient_cert'}display: none;{/empty} color: red;">上传成功</span>
                        <p class="notic2">请上传已申请证书中的 apiclient_cert.pem文件</p>
                    </dd>
                </dl>
                <dl class="row openOriginalRefund none">
                    <dt class="tit"><label for="wechat_apiclient_key">apiclient_key</label></dt>
                    <dd class="opt">
                        <input type="hidden" name="pay[pay_wechat_apiclient_key]" id="wechat_apiclient_key" value="{$userConfig.pay_wechat_apiclient_key|default=''}">
                        <a href="javascript:void(0);" class="ncap-btn ncap-btn-green" onclick="$('#apiclientClickID').attr('data-type', 'apiclient_key').trigger('click');">{empty name="$userConfig.pay_wechat_apiclient_key"}点击上传{else/}重新上传{/empty}</a>
                        <span style="{empty name='$userConfig.pay_wechat_apiclient_key'}display: none;{/empty} color: red;">上传成功</span>
                        <p class="notic2">请上传已申请证书中的 apiclient_key.pem文件</p>
                        <p class="notic2">微信支付平台API证书 <a href="https://kf.qq.com/faq/161222NneAJf161222U7fARv.html" target="_blank">查看教程</a></p>
                    </dd>
                </dl>

                <script type="text/javascript">
                    $(function() {
                        $('input[name="pay[pay_original_refund]"]').click(function() {
                            var value = $(this).val();
                            $('.openOriginalRefund').hide();
                            if (1 === parseInt(value)) $('.openOriginalRefund').show();
                        });

                        var payOriginalRefund = {$userConfig.pay_original_refund};
                        if (1 === parseInt(payOriginalRefund)) $('.openOriginalRefund').show();
                    });

                    // 文件上传
                    function apiclientClick(obj) {
                        // 获取文件路径名
                        var file = $(obj)[0].files[0];
                        var type = $(obj).attr('data-type');
                        var full_name = type ? type + '.pem' : '';
                        // 验证上传的文件
                        if (full_name == 'apiclient_cert.pem' && full_name != file.name) {
                            console.log('1');
                            $(obj).val('');
                            showErrorAlert('apiclient_cert 只允许上传 apiclient_cert.pem 文件');
                            return false;
                        } else if (full_name == 'apiclient_key.pem' && full_name != file.name) {
                            console.log('2');
                            $(obj).val('');
                            showErrorAlert('apiclient_key 只允许上传 apiclient_key.pem 文件');
                            return false;
                        }
                        // 验证上传格式
                        var fileName = file.name;
                        var fileExt = fileName.substr(fileName.lastIndexOf('.')).toLowerCase();
                        var ext = judgeExt(fileExt);
                        if (ext == -1) {
                            showErrorAlert('不支持选中的文件格式');
                            return false;
                        }
                        // 验证上传大小
                        var size = "{$upload_max_filesize}";
                        if (file.size > size) {
                            showErrorAlert('文件大小超过服务器限制');
                            return false;
                        }
                        // 定义上传数据
                        var formData = new FormData();
                        formData.append('file', file);
                        // 执行上传
                        layer_loading('上传本地');
                        $.ajax({
                            type: 'post',
                            url : "{:url('PayApi/file_upload')}",
                            data: formData,
                            contentType: false,
                            processData: false,
                            dataType: 'json',
                            xhr: function () {
                                myXhr = $.ajaxSettings.xhr();
                                if (myXhr.upload) {
                                    myXhr.upload.addEventListener('progress', function(e) {
                                        var curr = e.loaded;
                                        var total = e.total;
                                        process = parseInt(curr / total * 100);
                                        $('#wechat_' + type).parent().find('a').html('上传中...'+process+"%");
                                    });
                                }
                                return myXhr;
                            },
                            success: function (res) {
                                $(obj).val('');
                                layer.closeAll();
                                $('#wechat_' + type).parent().find('a').html('重新上传');
                                if (1 === parseInt(res.code)) {
                                    $('#wechat_' + type).val(res.data.file_url);
                                    $('#wechat_' + type).parent().find('span').show();
                                } else {
                                    showErrorAlert(res.msg);
                                }
                            }
                        });
                    }

                    // 验证格式
                    function judgeExt(ext) {
                        var type = "{$file_type}";
                        var extArr = [];
                        extArr = type.split("|");
                        var ext = ext.replace(".", "");
                        return extArr.indexOf(ext);
                    }
                </script>

                <dl class="row">
                    <dt class="tit">
                        <label for="username">快递公司</label>
                    </dt>
                    <dd class="opt" style="line-height: 30px;">
                        <a href="javascript:void(0);" onclick="SelectExpress();" class="ncap-btn ncap-btn-green">设置快递公司</a>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="username">运费模板</label>
                    </dt>
                    <dd class="opt" style="line-height: 30px;">
                        <label>
                            <input type="radio" name="shop[shop_open_shipping]" value="0" {if condition="!isset($userConfig.shop_open_shipping) || empty($userConfig.shop_open_shipping)"}checked="checked"{/if}/>包邮
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="shop[shop_open_shipping]" value="1" {if condition="$userConfig.shop_open_shipping == 1"}checked="checked"{/if}/>需要运费
                            &nbsp;<a id="a_shop_open_shipping" href="javascript:void(0);" onclick="SetShipping();" class="ncap-btn ncap-btn-green" {if condition="!isset($userConfig.shop_open_shipping) || empty($userConfig.shop_open_shipping)"}style="display:none;"{/if}>设置价格</a>
                        </label>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="uname">主营产品</label>
                    </dt>
                    <dd class="opt">
                        <label>
                            <input type="radio" name="shop[shop_type]" value="0" {if condition="!isset($userConfig.shop_type) || empty($userConfig.shop_type) || 2 == $userConfig.shop_type"}checked="checked"{/if}/>实物
                        </label>
                        &nbsp;&nbsp;&nbsp;
                        <label>
                            <input type="radio" name="shop[shop_type]" value="1" {if condition="$userConfig.shop_type == 1"}checked="checked"{/if}/>虚拟
                        </label>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="username">商品多规格</label>
                    </dt>
                    <dd class="opt" style="line-height: 30px;">
                        <input type="hidden" id="TestPass" name="TestPass" value="{$TestPass}">
                        <label><input type="radio" onclick="tag_call('shop_open', '{$TestPass}');" name="shop[shop_open_spec]" value="1" {if condition="$userConfig.shop_open_spec == 1"}checked="checked"{/if}/>开启</label>
                        &nbsp;&nbsp;&nbsp;
                        <label><input type="radio" name="shop[shop_open_spec]" value="0" {if condition="!isset($userConfig.shop_open_spec) || empty($userConfig.shop_open_spec)"}checked="checked"{/if}/>关闭</label>
                        <!--&nbsp;
                        <span id="a_shop_open_spec" {if condition="!isset($userConfig.shop_open_spec) || empty($userConfig.shop_open_spec)"}style="display:none;"{/if}>
                            <a href="javascript:void(0);" id='shop_open' onclick="tag_call('shop_open');" class="ncap-btn ncap-btn-green">标签调用</a>
                        </span>-->
                    </dd>
                </dl>
            </div>

            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                        <tr>
                            <th class="sign w10" axis="col0">
                                <div class="tc"></div>
                            </th>
                            <th abbr="article_title" axis="col3" class="w10">
                                <div class="tc">订单设置</div>
                            </th>
                            <th abbr="ac_id" axis="col4">
                                <div class=""></div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit" style="width: 120px;">
                        <label for="order_unpay_close_time">未付款关闭时间</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="order_unpay_close_time" name="order[order_unpay_close_time]" value="{$userConfig.order_unpay_close_time|default='0'}"/><span class="ml10">分钟</span>
                        <p class="notic">订单创建后多长时间未付款将自动关闭，订单自动关闭后商品库存将自动补回<br/><span style="color: red;">0表示不关闭未付款订单</span></p>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit" style="width: 120px;">
                        <label for="order_auto_receipt_time">发货后收货时间</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="order_auto_receipt_time" name="order[order_auto_receipt_time]" value="{$userConfig.order_auto_receipt_time|default='0'}"/><span class="ml10">天后</span>
                        <p class="notic">订单发货后自动收货时间<br/><span style="color: red;">0表示不自动确认收货</span></p>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit" style="width: 120px;">
                        <label for="order_right_protect_time">收货后可维权时间</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="order_right_protect_time" name="order[order_right_protect_time]" value="{$userConfig.order_right_protect_time|default='0'}"/><span class="ml10">天内</span>
                        <p class="notic">订单确认收货完成后，多长时间内可申请维权<br/><span style="color: red;">0表示订单不允许维权，修改为0仅影响修改之后的订单</span></p>
                    </dd>
                </dl>
            </div>

            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                        <tr>
                            <th class="sign w10" axis="col0">
                                <div class="tc"></div>
                            </th>
                            <th abbr="article_title" axis="col3" class="w10">
                                <div class="tc">评价设置</div>
                            </th>
                            <th abbr="ac_id" axis="col4">
                                <div class=""></div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>
            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit"> <label>商品评价</label> </dt>
                    <dd class="opt">
                        <label> <input type="radio" name="shop[shop_open_comment]" value="1" {if condition="$userConfig.shop_open_comment == 1"} checked="checked" {/if}/>开启 </label>
                        &nbsp;&nbsp;&nbsp;
                        <label> <input type="radio" name="shop[shop_open_comment]" value="0" {if condition="!isset($userConfig.shop_open_comment) || empty($userConfig.shop_open_comment)"} checked="checked" {/if}/>关闭 </label>
                    </dd>
                </dl>
                <dl class="row">
                    <dt class="tit"> <label>评价审核</label> </dt>
                    <dd class="opt">
                        <label> <input type="radio" name="shop[shop_open_comment_audit]" value="1" {if condition="$userConfig.shop_open_comment_audit == 1"} checked="checked" {/if}/>开启 </label>
                        &nbsp;&nbsp;&nbsp;
                        <label> <input type="radio" name="shop[shop_open_comment_audit]" value="0" {if condition="$userConfig.shop_open_comment_audit == 0"} checked="checked" {/if}/>关闭 </label>
                    </dd>
                </dl>
            </div>
            <div class="hDiv">
                <div class="hDivBox">
                    <table cellspacing="0" cellpadding="0" style="width: 100%">
                        <thead>
                        <tr>
                            <th class="sign w10" axis="col0">
                                <div class="tc"></div>
                            </th>
                            <th abbr="article_title" axis="col3" class="w10">
                                <div class="tc">商家收货信息</div>
                            </th>
                            <th abbr="ac_id" axis="col4">
                                <div class=""></div>
                            </th>
                        </tr>
                        </thead>
                    </table>
                </div>
            </div>

            <div class="ncap-form-default">
                <dl class="row">
                    <dt class="tit">
                        <label for="addr_contact_person">联系人</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="addr_contact_person" style="width: 30%;" name="addr[addr_contact_person]" value="{$userConfig.addr_contact_person|default=''}"/>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="addr_contact_phone">联系号码</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="addr_contact_phone" style="width: 30%;" maxlength="11" name="addr[addr_contact_phone]" value="{$userConfig.addr_contact_phone|default=''}"/>
                    </dd>
                </dl>

                <dl class="row">
                    <dt class="tit">
                        <label for="addr_shipping_addr">收货地址</label>
                    </dt>
                    <dd class="opt">
                        <input type="text" id="addr_shipping_addr" style="width: 30%;" name="addr[addr_shipping_addr]" value="{$userConfig.addr_shipping_addr|default=''}"/>
                    </dd>
                </dl>
            </div>
            
            <div class="ncap-form-default">
                <dl class="row">
                    <div class="bot">
                        <a href="JavaScript:void(0);" onclick="ShopConfig();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
                    </div>
                </dl>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">

    $(function(){
        try{
            if (typeof(eval('is_conceal_1649209614'))=="function" && is_conceal_1649209614()){
                $(".page").css("margin-left","");
                $(".page").css("min-width","");
            }else{
                $(".page").css("margin-left","100px");
                $(".page").css("min-width","auto");
            }
        }catch(e){}

        // 点击刷新数据
        $('.fa-refresh').click(function(){
            location.href = location.href;
        });

        $('input[name="shop[shop_open_shipping]"]').click(function() {
            var shop_open_shipping = $(this).val();
            if (1 == shop_open_shipping) {
                $('#a_shop_open_shipping').show();
            } else {
                $('#a_shop_open_shipping').hide();
            }
        });

        var ForceUse = $('#shop_force_use_wechat').val();
        if (1 == ForceUse) $('#shop_micro0').attr("disabled", "disabled");
    });

    // 设置快递公司
    function SelectExpress() {
        var url = "{:url('Shop/order_express', ['select'=>1])}";
        //iframe窗
        layer.open({
            type: 2,
            title: '设置快递公司',
            move: false,
            shadeClose: false,
            maxmin: false, //开启最大化最小化按钮
            shade: layer_shade,
            closeBtn: 3,
            area: ['60%', '80%'],
            content: url
        });
    }

    // 设置运费模板
    function SetShipping() {
        var url = "{:url('Shop/shipping_template')}";
        //iframe窗
        layer.open({
            type: 2,
            title: '运费模板管理',
            move: false,
            shadeClose: false,
            maxmin: false, //开启最大化最小化按钮
            shade: layer_shade,
            closeBtn: 3,
            area: ['60%', '80%'],
            content: url
        });
    }

    // 标签调用
    function tag_call(name, TestPass) {
        if (1 == TestPass) return false
        $.ajax({
            type: "POST",
            url: "{:url('System/ajax_tag_call', ['_ajax'=>1])}",
            data: {name:name},
            dataType: 'json',
            success: function (res) {
                if(res.code == 1){
                    //询问框
                    var layer_str = '<style type="text/css">.layui-layer-content{text-align:left!important;}</style>'+res.data.msg;
                    var confirm = layer.confirm(layer_str, {
                            shade: layer_shade,
                            move: false,
                            title: '提示',
                            btnAlign:'r',
                            closeBtn: 3,
                            area: ['50%','80%'],
                            btn: ['确定','取消'],
                            cancel: function(){
                                window.location.href = "{:url('Shop/conf',['close'=>1])}";
                            }
                        }, function (){
                            VerifyLatestTemplate(name);

                        }, 
                    );  
                }else{
                    layer.alert(res.msg, {icon: 2, title:false});
                }
            },
            error:function(e){
                layer.alert(e.responseText, {icon: 2, title:false});
            }
        });
    }

    // 检测文件是否最新版
    function VerifyLatestTemplate(name, is_close) {
        layer_loading('正在处理');
        $.ajax({
            type: "POST",
            url: "{:url('Shop/VerifyLatestTemplate', ['_ajax'=>1])}",
            data: {name:name, is_close:is_close},
            dataType: 'json',
            success: function (res) {
                layer.closeAll();
                if(res.code == 1){
                    layer.msg(res.msg, {icon: 1, time:1500}, function(){
                        window.location.href = "{:url('Shop/conf')}";
                    });
                }else{
                    layer.alert(res.msg, {
                        icon: 2, 
                        title: false,
                        cancel: function(){ 
                            window.location.href = "{:url('Shop/conf')}";
                        }
                    }, function(){
                        window.location.href = "{:url('Shop/conf')}";
                    });
                }
            },
            error:function(e){
                layer.closeAll();
                layer.alert(e.responseText, {icon: 2, title:false});
            }
        });
    }

    // 判断输入框是否为空
    function ShopConfig() {
        layer_loading('正在处理');
        $('#post_form').submit();
    }
</script>
{include file="public/footer" /}